package com.service;

import com.dao.MovesJdbc;
import com.model.Moves;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MovesService {
	MovesJdbc mj=new MovesJdbc();
	public List<Moves> show()  {
		List<Moves> list=new ArrayList<Moves>();
		ResultSet rs=mj.show();
		 try {
			while(rs.next()) {
				 int mid=rs.getInt("mid");
				 String file=rs.getString("file");
				 String author=rs.getString("author");
				 String time=rs.getString("time");
				 int hits=rs.getInt("hits");
				String statues=rs.getString("statues");
				 Moves move=new Moves(mid,file,author,time,hits,statues);
				 list.add(move);
			 }
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
    public void add(String file, String author, String time,String hits,String statues) {
        mj.add(file,author,time,hits,statues);
    }
	public void delete(String id) {
		mj.delete(id);
	}
	public Moves toupdate(String id) {
		ResultSet rs=mj.show();
		Moves moves=null;
		try {
			while (rs.next()) {
				int mid=rs.getInt("mid");
				if(id.equals(mid+"")) {
					String file=rs.getString("file");
					String author=rs.getString("author");
					String time=rs.getString("time");
					int hits=rs.getInt("hits");
					String statues=rs.getString("statues");
					 moves=new Moves(mid,file,author,time,hits,statues);
				}
				
				}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return moves;
	}
	public void update(String mid,String file, String author, String time,String hits,String statues) {
		mj.update(mid,file,author,time,hits,statues);
	}

}
